/**
 * @author [siwi]
 * @email [siwi@siwi.me]
 * @create date 2017-08-27 10:18:20
 * @modify date 2017-08-27 10:18:20
 * @desc [单例模式连接mongodb]
*/
const mongoose = require('mongoose')
mongoose.Promise = require('bluebird')
let __instance = (function () {
    let instance
    return (newInstance) => {
        if (newInstance) instance = newInstance
        return instance
    }
}())

class Siwi {
    constructor() {
        if (__instance()) return __instance()
            this.connect = mongoose.connect('mongodb://localhost/siwi', { useMongoClient: true })
        __instance(this)
    }
}
module.exports = new Siwi()